from django.test import TestCase

# Create your tests here.

import requests
import json
# 定义请求地址
addr = 'http://106.53.86.83:8888/'
login_url = '{}login/'.format(addr)
get_user_url = '{}getcookie/'.format(addr)
# 调用login接口
resp_login = requests.post(login_url, json={"user": "felix",
                                            "password": "123456"
                                            })
# 从login接口的返回中拿到cookie
cookie = resp_login.cookies
# 使用login接口返回的cookie，调用getcookie接口，进行测试动作
resp_get = requests.get(get_user_url,cookies = cookie)
# 拿到getcookie接口的返回报文
content = json.loads(resp_get.content)
# 判断返回报文是否符合业务逻辑。statu是S且msg中包含了cookie的归属felix这个字符
assert content['statu'] == 'S' and 'felix' in content['msg']
